package minefak3r;

/**
 *
 * @author Chriss & D4rky!
 */
public class Utils {

    public static String toHex(byte b) {
        String hexCode = java.lang.Integer.toHexString(b).toUpperCase();
        if (hexCode.length() < 2){
            hexCode = "0" + hexCode;
        }
        return "0x" + hexCode;
    }

    public static String getIP(String address) {
        if (address.equals("")) {
            return "";
        }
        char[] tex = address.toCharArray();
        int end = 0;
        for (int counter = 0; counter < address.length(); counter++) {
            if (String.valueOf(tex[counter]).equals(":")) {
                end = counter;
            }
        }
        return address.substring(0, end);
    }

    public static int getPort(String address) {
        if (address.equals("")) {
            return 0;
        }
        char[] tex = address.toCharArray();
        int start = 0;
        
        for (int counter = 0; counter < address.length(); counter++) {
            if (String.valueOf(tex[counter]).equals(":")) {
                start = counter;
            }
        }
        return Integer.valueOf(address.substring(start + 1, address.length()));
    }
}
